package com.mirstone.jetpackdemo.room;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import com.mirstone.jetpackdemo.App;
import com.mirstone.jetpackdemo.R;
import com.mirstone.jetpackdemo.databinding.ActivityAddUserBinding;

public class AddUserActivity extends AppCompatActivity {
    private static final String TAG = "AddUserActivity";
    private ActivityAddUserBinding binding;
    private User user;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_add_user);

        user = new User();
        binding.setUser(user);
        binding.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (user.getName() == null || user.getIdCard() == null){
                    Toast.makeText(AddUserActivity.this, "请输入姓名或身份证", Toast.LENGTH_SHORT).show();
                    return;
                }
                user.setCar(user.getName());
                user.setDog(user.getName());
                long insert = App.getAppDataBase().userDao().insert(user);
                Log.d(TAG, "onClick: " + insert);
                finish();
            }
        });
    }
}